(function (vc) {

    vc.extends({
        data: {
            addFloorShareInfo: {
                fsmId: '',
                floorId: '',
                floorNum: '',
                meterType: '',
                meterNum: '',
                shareType: '',
                formulaValue: '',
                configId: '',
                sharePrice: '',
                feeConfigs: []

            }
        },
        _initMethod: function () {

        },
        _initEvent: function () {
            vc.on('addFloorShare', 'openAddFloorShareModal', function (_param) {
                vc.copyObject(_param, $that.addFloorShareInfo);
                $that._loadAddFeeConfig();
                $('#addFloorShareModel').modal('show');
            });
        },
        methods: {
            addFloorShareValidate() {
                return vc.validate.validate({
                    addFloorShareInfo: $that.addFloorShareInfo
                }, {
                    'addFloorShareInfo.floorId': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "楼栋ID不能为空"
                        },
                        {
                            limit: "maxLength",
                            param: "30",
                            errInfo: "楼栋ID不能超过30"
                        },
                    ],
                    'addFloorShareInfo.meterType': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "表类型不能为空"
                        },
                        {
                            limit: "maxLength",
                            param: "12",
                            errInfo: "表类型不能超过12"
                        },
                    ],
                    'addFloorShareInfo.meterNum': [
                        {
                            limit: "maxLength",
                            param: "64",
                            errInfo: "表编号不能超过64"
                        },
                    ],
                    'addFloorShareInfo.shareType': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "公摊方式不能为空"
                        },
                        {
                            limit: "maxLength",
                            param: "12",
                            errInfo: "公摊方式不能超过12"
                        },
                    ],
                });
            },
            saveFloorShareInfo: function () {
                if (!$that.addFloorShareValidate()) {
                    vc.toast(vc.validate.errInfo);

                    return;
                }

                $that.addFloorShareInfo.communityId = vc.getCurrentCommunity().communityId;

                vc.http.apiPost(
                    '/meter.saveFloorShareMeter',
                    JSON.stringify($that.addFloorShareInfo),
                    {
                        emulateJSON: true
                    },
                    function (json, res) {
                        //vm.menus = vm.refreshMenuActive(JSON.parse(json),0);
                        let _json = JSON.parse(json);
                        if (_json.code == 0) {
                            //关闭model
                            $('#addFloorShareModel').modal('hide');
                            $that.clearAddFloorShareInfo();
                            vc.emit('floorShare', 'listFloorShare', {});

                            return;
                        }
                        vc.toast(_json.msg);

                    },
                    function (errInfo, error) {
                        console.log('请求失败处理');

                        vc.toast(errInfo);

                    });
            },
            clearAddFloorShareInfo: function () {
                $that.addFloorShareInfo = {
                    fsmId: '',
                    floorId: '',
                    floorNum: '',
                    meterType: '',
                    meterNum: '',
                    shareType: '',
                    formulaValue: '',
                    configId: '',
                    sharePrice: '',
                    feeConfigs: []

                };
            },
            _loadAddFeeConfig: function (_feeTypeCd) {

                let param = {
                    params: {
                        page: 1,
                        row: 500,
                        communityId: vc.getCurrentCommunity().communityId,
                        feeTypeCd: '888800010017',
                        isDefault: 'F',
                        state: 'Y'
                    }
                };
                //发送get请求
                vc.http.apiGet('/feeConfig.listFeeConfigs',
                    param,
                    function (json, res) {
                        let _json = JSON.parse(json);
                        $that.addFloorShareInfo.feeConfigs = _json.feeConfigs;
                    },
                    function (errInfo, error) {
                        console.log('请求失败处理');
                    });
            },
        }
    });

})(window.vc);
